
#include "C:\SAFIRE\Y\Y_BIFn\Y_BIFn.y.h"

#include "C:\SAFIRE\Y\PH_SL.y.h"

#include "C:\SAFIRE\Y\Mgt_SL.y.h"

#include "C:\SAFIRE\Y\ConfigUdp_TP.y.h"

#include "C:\SAFIRE\Users\SIP_USER\ws\SIP\source\Common_LIB\Scenario_HTML_Gen.y.h"

#include "C:\SAFIRE\USERS\SIP_USER\ws\SIP\source\SIP_LIB\SIP_LIB.y.h"


typedef SIP_ST_RG_RT_V [SIP_Signals_T SIP_G, PH_SL UDP_Data_G, Mgt_SL UDP_Mgt_G]
{
    TIMER SIGNAL        TSupervisor();
    TIMER SIGNAL        TAct_Rq();
    TIMER SIGNAL        TWaitOK();
    TIMER SIGNAL        TStart();
    TIMER SIGNAL		TPostamble();
	TIMER SIGNAL		TWaitRegister();
	       
    Request_T           Request_TX_1;
    
    Response_T          Response_T_TX_1;
    Response_T          Response_T_TX_2;
    Response_T          Response_T_RX_1;
    Response_T          Response_T_RX_2;
    
    Request_Line_T      Request_Line;
    Message_Headers_T   Message_Headers;
    Message_Body_T      Message_Body;
    Status_Line_T       Status_Line;
    
    PH_SL               PH_SL_S;
    SIP_Signals_T       SIP_Signal;    
    Config_UDP_T        ConfigUDP;
    
    STRING              CRLF;
        
    STRING              ScenarioName;
    STRING              ScenarioDecription;
    STRING              HTML_Title;
    STRING              HTMLFilePath;
    STRING              Mode;
    STRING				SIP_Version_Tester;
    STRING              Tester_Dispaly_Name;
    STRING				Supported_Tester;
    STRING				Tag_Tester;
	STRING				Allow_Tester;
	
    NUMBER              HTML_File;
	NUMBER				Retry_Cancel;
	
	SIP_Addr_Spec_T		SUT_Addr;
	SIP_Addr_Spec_T		Tester_Addr;
	
  
    SUT_Addr.SIP_URI.UserInfo.User = "1000";
	SUT_Addr.SIP_URI.UserInfo.Password = NULL;	
	SUT_Addr.SIP_URI.HostPort.Host = "10.0.1.40";
	SUT_Addr.SIP_URI.HostPort.Port = ?;	
	SUT_Addr.SIP_URI.URI_Parameters = NULL;
	SUT_Addr.SIP_URI.URI_Headers = NULL;
	
    Tester_Addr.SIP_URI.UserInfo.User = "1000";
	Tester_Addr.SIP_URI.UserInfo.Password = NULL;	
	Tester_Addr.SIP_URI.HostPort.Host = "10.0.1.109";
	Tester_Addr.SIP_URI.HostPort.Port = 5060;	
	Tester_Addr.SIP_URI.URI_Parameters = NULL;
	Tester_Addr.SIP_URI.URI_Headers = NULL;
    
    Tag_Tester 				= "tag=a3bhg";
	SIP_Version_Tester		= "SIP/2.0";
	Callid_Tester			= "6E98FD28E9734BAABC1EE1E5DBA2A7B50x0a00019d";
    Tester_Dispaly_Name     = "UA1";
	Supported_Tester		= "replaces,norefersub,timer";
    Allow_Tester 			= "Allow: INVITE, ACK, BYE, CANCEL, REFER, OPTIONS, REGISTER, SUBSCRIBE";
	
    
    Request_Line.Method.Register.MustBeNull = NULL;
    Request_Line.Request_URI.Addr_Spec.SIP_URI.HostPort.Host = SUT_Addr.SIP_URI.HostPort.Host;
    Request_Line.SIP_Version = SIP_Version_Tester;
	
    Message_Headers.Call_Id.Callid.Token = Callid_Tester;
    Message_Headers.CSeq.Cseq_Number = 1;
    Message_Headers.CSeq.Method.Register.MustBeNull = NULL;
    Message_Headers.From.From_Spec.Addr.Name_Addr.Addr_Spec.SIP_URI = Tester_Addr.SIP_URI;
    Message_Headers.From.From_Spec.From_Param_List.Token = Tag_Tester;     
    Message_Headers.To.To_Spec.Addr.Name_Addr.Addr_Spec.SIP_URI = SUT_Addr.SIP_URI;
    Message_Headers.CSeq.Cseq_Number = 2;
    Message_Headers.CSeq.Method.Register.MustBeNull = NULL;
    Message_Headers.Via.Via_Param_List.Via_Param.Sent_Protocol.Token = SIP_Version_Tester; 
    Message_Headers.Via.Via_Param_List.Via_Param.Sent_by.HostPort = Tester_Addr.SIP_URI.HostPort;
    Message_Headers.Via.Via_Param_List.Via_Param.Via_Params_List.Token = "branch=z9hG4bK0a00016d000000184ad450650000109d00000000;rport";	
    Message_Headers.Max_Forwards.Max_Forwards_Number = 70;	
    Message_Headers.Contact.Contact_Spec.Contact_Param_List.Contact_Param.Addr.Name_Addr.Display_Name.As_Quoted_String.Quoted_String = Tester_Dispaly_Name;
    Message_Headers.Contact.Contact_Spec.Contact_Param_List.Contact_Param.Addr.Name_Addr.Addr_Spec.SIP_URI.HostPort.Host = Tester_Addr.SIP_URI.HostPort.Host; 
	IF (Supported_Tester EQ "") Message_Headers.Supported =  NULL;
    ELSE Message_Headers.Supported.Option_Tag_List.Token_List =  Supported_Tester;
    Message_Headers.User_Agent.Server_Val_List.Token_List = "SAFIRE 4G - SIP Signaling Tester";
	Message_Headers.Content_Length.ContentLength = 0;
    
    Request_TX_1.Request_Line       = Request_Line;
    Request_TX_1.Message_Headers    = Message_Headers;
	
    Mode= "ab";
    HTMLFilePath= "C:\\SAFIRE\\Temp\\SIP_ST_RG_RT_V.html";    
    
    HTML_File= OpenFile( HTMLFilePath,
                         Mode);
    IF (HTML_File EQ 0)
    {
        Print( "SIP_ST_CC_OE_CE - Can't open C:\\SAFIRE\\Temp\\");
        Print( "SIP_ST_CC_OE_CE - Please create this directory C:\\SAFIRE\\Temp\\");
        STOP;
    }
                             
    HTML_Title = "SIP_ST_RG_RT_V";
    ScenarioName = "SIP_ST_RG_RT_V";
    ScenarioDecription = "basic call - passive part";
    Scenario_Gen_HTML_Header( HTML_File,
                              HTML_Title,
                              ScenarioName,
                              ScenarioDecription);

    START TStart FOR 1000;
    Print("\n\nScenario_1 : ---  started");
    
    ? .TStart()
    {
         Print("\n\nScenario_1 : ---  started");
         :: Preamble;
    }        
     
    
    STATE Preamble
    {        
        Print("SIP_ST_RG_RT_V - Start UDP config");
        ConfigUDP.Src.IpAddress=        Tester_Addr.SIP_URI.HostPort.Host;
        ConfigUDP.Src.Port=             Tester_Addr.SIP_URI.HostPort.Port;
        
        ConfigUDP.Dst.IpAddress=        SUT_Addr.SIP_URI.HostPort.Host;
        ConfigUDP.Dst.Port=             SUT_Addr.SIP_URI.HostPort.Port;
        
        ConfigUDP.MaxPacketSize=        1024;
        Print("SIP_ST_RG_RT_V - End UDP config");

        Print("SIP_ST_RG_RT_V - Configuring UDP");
        UDP_Mgt_G ! Mgt_SL.Configure( ConfigUDP);
        
        Print("SIP_ST_RG_RT_V - Activating UDP");
        UDP_Data_G ! PH_SL.PH_Act_Rq();
        START TAct_Rq FOR 10000;
    
        UDP_Data_G ? PH_SL.PH_Act_Ind() : PH_SL_S 
        {
            Print( "SIP_ST_RG_RT_V - UPD Activated");
            START TSupervisor FOR 10000;
            
            Scenario_Gen_HTML_Verdict( HTML_File, 0, "PASS", "UDP activated");
            START TWaitRegister FOR 5000;
			:: Wait_Register;
        }
        
        UDP_Data_G ? PH_SL.PH_Deact_Ind() : PH_SL_S 
        {
            Print( "SIP_ST_RG_RT_V - UPD Act_Rq not successfull  ... PH_Deact_Ind received!");
            
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "UPD Act_Rq not successfull  ... PH_Deact_Ind received!");            
            STOP;
        }
        
        ? .TAct_Rq()
        {
            Print( "SIP_ST_RG_RT_V - UPD Act_Req not received  ... Timeout!");
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "UPD Act_Req not received  ... timeout!");
            STOP;
        }                
    }  
    
    STATE Wait_Register
    {
        Print("SIP_ST_RG_RT_V - Starting");
		SIP_G ? SIP_Signals_T.SIP_Register (?) : SIP_Signal;
        {
			Request_RX_1 = SIP_Signal.SIP_Invite.Request;
			Print("SIP_ST_RG_RT_V - VERDICT: PASS! - SIP_Register message received");
			Scenario_Gen_HTML_Verdict( HTML_File, 1, "PASS", "SIP_Register received");
			
			Status_Line 											= NULL;
			Status_Line.SIP_Version 								= SIP_Version_Tester;
			Status_Line.Status_Code 								= 200;
			Status_Line.Reason_Phrase.Token_List 					= "OK";
			
			Message_Headers 										= NULL;
			Message_Headers.CSeq 									= Request_RX_1.Message_Headers.CSeq;
			Message_Headers.Call_Id 								= Request_RX_1.Message_Headers.Call_Id;
			Message_Headers.Contact 								= Request_RX_1.Contact;
			Message_Headers.Contact.Contact_Spec.Contact_Param_List.Contact_Param.Contact_Params.Token = "expires=3600";
			Message_Headers.From									= Request_RX_1.Message_Headers.From;
			Message_Headers.To.To_Spec.Addr							= Request_RX_1.Message_Headers.To.To_Spec.Addr;
			Message_Headers.To.To_Spec.To_Param_List.Token 			= Tag_Tester;
			Message_Headers.Via 									= Request_RX_1.Message_Headers.Via;
			Message_Headers.User_Agent.Server_Val_List.Token_List 	= "SAFIRE 4G - SIP Signaling Tester";
			Message_Headers.Expires									= 3600;
			Message_Headers.Date.SIP_Date.Token_List				= "Fri, 23 Oct 2009 12:03:09 GMT";
			Message_Headers.Content_Length.ContentLength 			= 0;
			
			Response_T_TX_1.Status_Line = Status_Line;
			Response_T_TX_1.Message_Headers = Message_Headers;
			
			
			SIP_G ! SIP_Signals_T.SIP_200_OK (Response_T_TX_1);
			Print("SIP_ST_RG_RT_V - SIP_200_OK sent");
			START TPostamble FOR 2000;
            :: Postamble;
		}        
    }
    
    
    
    STATE Postamble
    {
		? .TPostamble()
        {
			Print("SIP_ST_RG_RT_V - ... ending the test scenario");
			UDP_Data_G ! PH_SL.PH_Deact_Rq();
			Scenario_Gen_HTML_Footer( HTML_File);
			CloseFile( HTML_File);
			STOP;
		}
    }


};